<?php
if(cr('GeneralConfig.allow_comment_on_gallery') != '1')
{
	echo sprintf(__('Gallery comments are disabled to enable them go to %s page.'),$html->link(__('general settings'),'/admin/site_config/setting/General'));
}else
{
	$index->setData($assetComments,'AssetComment');
	
	$index->showFields(array('id','body','image',array('user_id'=>__('Posted By')),'created'));
	$index->sortableFields(array('id',array('body'=>'Comment'),array('created'=>'Date')));
	
	$index->setAction(__('Edit'),'/admin/asset_comments/edit/:AssetComment.id');
	$index->setAction(__('Delete'),'/admin/asset_comments/delete/:AssetComment.id');
	$index->setAction(null,null,$this->helpers,false,true,'publish_unpublish');
	
	$index->addColumn('created','showFormatedDate');
	$index->addColumn('user_id','setPosterName');
	$index->addColumn('image','setImage');
	$index->addColumn('body','showLimitedBodyWords');
	
	$index->addButton(__("Delete Selected"),array("action"=>"bulkDelete",'admin'=>true));
	$index->addButton(__("Unpublish Selected"),array("action"=>"bulkUnpublish",'admin'=>true));
	$index->addButton(__("Publish Selected"),array("action"=>"bulkPublish",'admin'=>true));
	
	function showFormatedDate($record)
	{
		return date('Y-m-d',strtotime($record['AssetComment']['created']));
	}
		
	function setPosterName($record)
	{
		return $record['AssetComment']['poster']['display_name'];
	}

	function setImage($record, $index)
	{
		return $index->Html->image($record['ListingAsset']['file_url'],array('thumb'=>array('crop'=>true,'width'=>60,'height'=>60)));
	}
	
	function showLimitedBodyWords($record)
	{
		uses('Flay');		
		return Flay::fragment($record['AssetComment']['body'],20);		
	}
		
	function publish_unpublish($model,$record)
	{
		if($record[$model]['status'] == AssetComment::PUBLISHED)
		{
			$action['title'] = __('Unpublish');
			$action['url'] = '/admin/asset_comments/changeStatus/unpublish/'.$record[$model]['id'];
		}else
		{
			$action['title'] = __('Publish');
			$action['url'] = '/admin/asset_comments/changeStatus/publish/'.$record[$model]['id'];
		}
		return $action;
	}
	$index->setPaginateSeparator(' ');
	echo $index->display();
}

?>